home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS_SCSI Code (In Development) / DTS_SCSI_Driver.a < prev    next >
Encoding:
Text File  |  1993-01-15  |  6.6 KB  |  178 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        DTS_SCSI_Driver.a
  3. ;
  4. ;
  5. ;
  6. ;    Unfortunately, no matter how long awaited, it's still not done.  In fact, this
  7. ;    isn't even a release- this is just an image of the code taken in the middle of
  8. ;    development.
  9. ;
  10. ;    THIS CODE DOES NOT WORK AS A WHOLE.  MUCH OF IT IS BUGGY AND / OR INCOMPLETE.
  11. ;    YOU WOULD HAVE TO BE ABSOLUTELY INSANE TO USE ANY OF THIS CODE IN YOUR
  12. ;    PROJECT WITHOUT EXTENSIVE THOUGHT, DEBUGGING AND TESTING.
  13. ;
  14. ;
  15. ;
  16. ;
  17. ;    Contains:    standard installation stubs, driver header, entry/exit points, and static data
  18. ;
  19. ;    Written by:    Craig Prouse
  20. ;
  21. ;    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  22. ;
  23. ;    Change History (most recent first):
  24. ;
  25. ;         <8>    04/24/92    tmd        added BlockOffset to find start of Memory Mgr block;
  26. ;                                    changed icon file variable to &iconFile
  27. ;         <7>    11/25/91    chp        remove ASYNC bit dependency from IOReturn2 to improve support
  28. ;                                    for asynchronous drivers, explicitly return result in parameter
  29. ;                                    block for  immediate calls, and adjust padding
  30. ;         <6>    10/25/91    chp        use better (FORCEACTIVE) method for preventing dead-strip,
  31. ;                                    documented in MPW 3.2 release notes
  32. ;         <5>    10/17/91    chp        modify so that installation code is not dead-stripped by the
  33. ;                                    Link tool
  34. ;         <4>    10/17/91    chp        add support for SCSI driver installation procedure
  35. ;         <3>    10/16/91    chp        improve support for generating and including drive icon data at
  36. ;                                    build time
  37. ;         <2>    10/15/91    chp        update header contents
  38. ;         <1>    10/15/91    chp        first checked in
  39. ;
  40. ;    To Do:
  41. ;
  42.             case    on
  43.             print    push,off
  44.             include    'SysEqu.a'
  45.             print    pop
  46.  
  47. ; Our current driver version number, to be included in driver header.
  48. ; This must match the one in DTS_SCSI_Driver.h!
  49. DriverVersion equ    1        
  50.  
  51. ;
  52. ; Our main entry point. At boot time, the SCSI boot code loads this code into memory,
  53. ; locks it down, and JSRs to it. This code is responsible for installing the driver
  54. ; (which immediately follows this entry-point code).
  55. ;
  56. ; Note: This code must be loaded into a nonrelocateable (NewPtr) block in the
  57. ; system heap; the deallocation code in Install.c and in Application.c requires it!
  58. ;
  59. GInstall    proc    export, forceactive
  60.             import    InstallProc, OpenFunc, PrimeFunc, ControlFunc, StatusFunc, CloseFunc
  61.  
  62. ;
  63. ; SCSI disk drivers are loaded at boot time and called to install themselves. The boot code in
  64. ; ROM passes some parameters in very strange places, making C implementations just a bit tricky.
  65. ; Here we move those parameters from their original registers, onto the stack for a C function
  66. ; with the following prototype:
  67. ;
  68. ;    void InstallProc (Partition *partitionMap, long scsiID, Ptr sbData);
  69. ;
  70.             move.l    d7,-(sp)                    ; default data area (rarely used)
  71.             move.l    d5,-(sp)                    ; SCSI ID of device this driver came from
  72.             move.l    a0,-(sp)                    ; pointer to the drive's partition table
  73.             bsr        InstallProc
  74.             lea        12(sp),sp
  75.             rts
  76.             
  77. DrvrStart    proc    export
  78.             import    OpenFunc, PrimeFunc, ControlFunc, StatusFunc, CloseFunc
  79.             export    DrvrHdr
  80.             
  81. BlockOffset    dc.l    (DrvrHdr - GInstall)        ; Distance to start of Memory Mgr block
  82.                                                 ;  so we can find the pointer to unload
  83.                                                 ;  it if we wish to dispose of the driver
  84.  
  85. ; This is a standard 'DRVR' resource header
  86. ;
  87. DrvrHdr                            ; Actual start of driver for MacOS
  88. @drvrFlags    dc.w    $4F00        ; flags meaning "read, write, control, status, needsLock"
  89. @drvrDelay    dc.w    0
  90. @drvrEvent    dc.w    0
  91. @drvrMenu    dc.w    0
  92. @drvrOpen    dc.w    GOpen - DrvrHdr
  93. @drvrPrime    dc.w    GPrime - DrvrHdr
  94. @drvrCtl    dc.w    GControl - DrvrHdr
  95. @drvrStatus    dc.w    GStatus - DrvrHdr
  96. @drvrClose    dc.w    GClose - DrvrHdr
  97. @drvrName    dc.b    '.DTS_SCSI' ; name must match the one in DTS_SCSI_Driver.h!
  98. drvrVers    dc.b    DriverVersion
  99.             align    4
  100.  
  101. ;
  102. ; Following are assembly language glue routines which call C language driver routine
  103. ; implementations and manage the driver return process through either a simple RTS
  104. ; or the JIODone vector, as appropriate. The required C functions are as indicated:
  105. ;
  106. ;    OSErr OpenFunc (ParmBlkPtr pb, DCtlPtr dce);
  107. ;    OSErr PrimeFunc (ParmBlkPtr pb, DCtlPtr dce);
  108. ;    OSErr ControlFunc (ParmBlkPtr pb, DCtlPtr dce);
  109. ;    OSErr StatusFunc (ParmBlkPtr pb, DCtlPtr dce);
  110. ;    OSErr CloseFunc (ParmBlkPtr pb, DCtlPtr dce);
  111. ;
  112. GOpen        move.b    drvrVers,dCtlQueue+1(a1)    ; register driver version number
  113.             movem.l    a0-a1,-(sp)                    ; save ParmBlkPtr, DCtlPtr across function call
  114.             movem.l    a0-a1,-(sp)                    ; push ParmBlkPtr, DCtlPtr for C
  115.             bsr        OpenFunc                    ; call linked C
  116.             addq.l    #8,sp                        ; clean up the stack
  117.             movem.l    (sp)+,a0-a1                    ; restore ParmBlkPtr, DCtlPtr
  118.             rts                                    ; Open always uses synchronous RTS            
  119.  
  120. GPrime        movem.l    a0-a1,-(sp)                    ; save ParmBlkPtr, DCtlPtr across function call
  121.             movem.l    a0-a1,-(sp)                    ; push ParmBlkPtr, DCtlPtr for C
  122.             bsr        PrimeFunc                    ; call linked C
  123.             addq.l    #8,sp                        ; clean up the stack
  124.             bra.s    IOReturn
  125.  
  126. GControl    movem.l    a0-a1,-(sp)                    ; save ParmBlkPtr, DCtlPtr across function call
  127.             movem.l    a0-a1,-(sp)                    ; push ParmBlkPtr, DCtlPtr for C
  128.             bsr        ControlFunc                    ; call linked C
  129.             addq.l    #8,sp                        ; clean up the stack
  130.             movem.l    (sp)+,a0-a1                    ; restore ParmBlkPtr, DCtlPtr
  131.             cmpi.w    #killCode,csCode(a0)        ; test for KillIO call (special case)
  132.             bne.s    IOReturn2
  133.             rts                                    ;    KillIO must return via RTS
  134.  
  135. GStatus        movem.l    a0-a1,-(sp)                    ; save ParmBlkPtr, DCtlPtr across function call
  136.             movem.l    a0-a1,-(sp)                    ; push ParmBlkPtr, DCtlPtr for C
  137.             bsr        StatusFunc                    ; call linked C
  138.             addq.l    #8,sp                        ; clean up the stack
  139.  
  140. IOReturn    movem.l    (sp)+,a0-a1                    ; restore ParmBlkPtr, DCtlPtr
  141. IOReturn2    move.w    ioTrap(a0),d1
  142.             btst    #noQueueBit,d1                ; test IMMED bit
  143.             beq.s    @Queued                        ;    IMMED calls not queued, so RTS
  144.             move.w    d0,ioResult(a0)                ;    with result explicitly in ioResult
  145.             rts
  146.  
  147. @Queued        tst.w    d0                            ; test asynchronous return result
  148.             bgt.s    @RTS                        ;    async I/O is incomplete if result > 0, so RTS
  149. @JIODone    move.l    (JIODone).w,-(sp)            ; set up jIODone return vector
  150. @RTS        rts
  151.  
  152. GClose        movem.l    a0-a1,-(sp)                    ; save ParmBlkPtr, DCtlPtr across function call
  153.             movem.l    a0-a1,-(sp)                    ; push ParmBlkPtr, DCtlPtr for C
  154.             bsr        CloseFunc                    ; call linked C
  155.             addq.l    #8,sp                        ; clean up the stack
  156.             movem.l    (sp)+,a0-a1                    ; restore ParmBlkPtr, DCtlPtr
  157.             rts                                    ; Close always synchronous RTS
  158.  
  159.             endmain
  160.  
  161. DriveIcon    proc    export
  162.  
  163. ; Data for the drive icon is generated from a resource file by a shell script at build
  164. ; time. The shell script creates an include file with a series of DC directives and the
  165. ; project build script passes in the name of the include file as a SET variable.
  166. ;
  167. ; &IconFile should be passed in as a command line option to the Asm tool, e.g.:
  168. ;
  169. ;    Asm -define &IconFile="∂'DTS_SCSI.Icon.a∂'" DTS_SCSI.a
  170. ;
  171.             include    &IconFile
  172.             
  173. WhereStr    dc.b    'DTS SCSI Drive'
  174.             align    4
  175.             
  176.             endproc
  177.             end
  178.